'''
Created on 01/10/2011

@author: Cesar Oswaldo Rubio Jaime
'''
import unittest
from Logger import Logger
from Logger import MSG_DEBUG, MSG_ERROR, MSG_WARN, MSG_INFO, MSG_FATAL

class TestLogger(unittest.TestCase):
        
    def setUp(self):
        self.logger = Logger()
            
    def testCreateLogger(self):
        self.assertIsInstance(self.logger, Logger, "Error creating a new Logger")

    def testCreateTwoLoggers(self):
        logger1 = Logger()
        logger2 = Logger()
        self.assertIsNot(logger1, logger2, "Logger instances are not different")
        
    def testDebugMessage(self):
        self.assert_(self.logger.debug("Debug testing..."), "Debug message failed")
        
    def testWarnMessage(self):
        self.assert_(self.logger.warn("Warning testing..."), "Warning message failed")
        
    def testErrorMessage(self):
        self.assert_(self.logger.error("Error testing..."), "Error message failed")

    def testInfoMessage(self):
        self.assert_(self.logger.info("Info testing..."), "info message failed")
        
    def testFatalMessage(self):
        self.assert_(self.logger.fatal("Fatal testing..."), "Fatal message failed")
        
    def testShowMessage(self):
        self.assert_(self.logger.showMessage("Debug message", MSG_DEBUG), "Show message failed with MSG_DEBUG")
        self.assert_(self.logger.showMessage("Warning message", MSG_WARN), "Show message failed with MSG_WARN")
        self.assert_(self.logger.showMessage("Info message", MSG_INFO), "Show message failed with MSG_INFO" )
        self.assert_(self.logger.showMessage("Debug message", MSG_ERROR), "Show message failed with MSG_ERROR")
        self.assert_(self.logger.showMessage("Debug message", MSG_FATAL), "Show message failed with MSG_FATAL")
        
    def testGetTarget(self):
        self.assertEquals(self.logger.getTarget(), "xml", "getTarget returned different value")

    def testSetAndGetNDC(self):
        self.assertEqual(self.logger.getNDC(), "", "Set and Get NDC failed when is empty")
        self.logger.pushNDC("Message1")
        self.assertEqual(self.logger.getNDC(), "Message1", "Set and Get NDC failed with one value")
        self.logger.pushNDC("Message2")
        self.assertEqual(self.logger.getNDC(), "Message1 Message2", "Set and Get NDC failed")
        
    def testTracestack(self):
        self.assertEqual(self.logger.tracestack(), None , "Something was wrong, there is a tracestack")   
        
if __name__ == "__main__":
    unittest.main()